<template>
  <!-- <a-tooltip>
    <template #title>prompt text</template>
    Tooltip will show when mouse enter. -->
  <div style="position: relative">
    <bm-overlay
      ref="customOverlay"
      :class="{
        sampleToolTip: true,
        active,
        height_200: data.isShowMarkToopTip,
        height_0: !data.isShowMarkToopTip
      }"
      pane="labelPane"
      @draw="draw"
    >
      <!-- <div>设备ID:{{ data.id }}</div>
      <div>设备编号:{{ data.gid }}</div>
      <div>设备名称:{{ data.title }}</div>
      <div>设备经度:{{ data.lng }}</div>
      <div>设备纬度:{{ data.lat }}</div>
      <div>设备状态:{{ data.status }}</div> -->
      <div class="card">
        <div class="header">{{ disposeStrLengthFunc(data.title) }}</div>
        <div class="body">
          <div class="skill">
            <div class="skill-name">设备ID</div>
            <div class="skill-percent-number">{{ data.id }}</div>
          </div>
          <div class="skill">
            <div class="skill-name">设备编号</div>
            <div class="skill-percent-number">{{ data.gid }}</div>
          </div>
          <div class="skill">
            <div class="skill-name">设备经度</div>
            <div class="skill-percent-number">{{ data.lng }}</div>
          </div>
          <div class="skill">
            <div class="skill-name">设备纬度</div>
            <div class="skill-percent-number">{{ data.lat }}</div>
          </div>
          <div class="skill">
            <div class="skill-name">设备状态</div>
            <div class="skill-percent-number">{{ data.status }}</div>
          </div>
          <div class="skill">
            <div class="skill-name">检测时间</div>
            <div class="skill-percent-number">{{ data.checkTime }}</div>
          </div>
          <a-card class="param_card">
            <div class="param_box">
              <p class="p_param_title">参数信息</p>
              <a-list size="small" bordered :data-source="data.paramDataList">
                <template #renderItem="{item}">
                  <a-list-item class="param_item">
                    <p>
                      <span class="param_name"> {{ item.checkDataName }}：</span>
                      <span class="param_value">{{ item.checkDataValue }}</span>
                      <span class="param_unit">{{ item.checkDataUnit }}</span>
                      <span
                        class="param_status"
                        :style="`color:${
                          item.paramStatus == '适宜'
                            ? '#21ad58'
                            : item.paramStatus == '偏高'
                            ? '#f0545a'
                            : '#f8b54c'
                        }`"
                        >{{ item.paramStatus }}</span
                      >
                    </p>
                  </a-list-item>
                </template>
              </a-list>
            </div>
          </a-card>
          <!-- <div class="param_box">
            <div class="param_card">
              <div class="title"></div>
              <div class="data">
                <p>39,500</p>

                <div class="range">
                  <div class="fill"></div>
                </div>
              </div>
            </div>
            <div class="param_card">
              <div class="title"></div>
              <div class="data">
                <p>39,500</p>

                <div class="range">
                  <div class="fill"></div>
                </div>
              </div>
            </div>
            <div class="param_card">
              <div class="title"></div>
              <div class="data">
                <p>39,500</p>

                <div class="range">
                  <div class="fill"></div>
                </div>
              </div>
            </div>
            <div class="param_card">
              <div class="title"></div>
              <div class="data">
                <p>39,500</p>

                <div class="range">
                  <div class="fill"></div>
                </div>
              </div>
            </div>
            <div class="param_card">
              <div class="title"></div>
              <div class="data">
                <p>39,500</p>

                <div class="range">
                  <div class="fill"></div>
                </div>
              </div>
            </div>
            <div class="param_card">
              <div class="title"></div>
              <div class="data">
                <p>39,500</p>

                <div class="range">
                  <div class="fill"></div>
                </div>
              </div>
            </div>
          </div> -->
        </div>
      </div>
    </bm-overlay>
  </div>
  <!-- </a-tooltip> -->
</template>

<script>
  export default {
    props: ['text', 'position', 'active', 'data'],
    watch: {
      position: {
        handler() {
          this.$refs.customOverlay.reload()
        },
        deep: true
      }
    },
    methods: {
      handleClick() {
        global.alert('Well done.')
      },
      draw({el, BMap, map}) {
        const {lng, lat} = this.position
        const pixel = map.pointToOverlayPixel(new BMap.Point(lng, lat))
        console.log(pixel, 'pixel')
        if (pixel.y > 20) {
          el.style.left = pixel.x - 360 + 'px'
          el.style.top = pixel.y - 280 + 'px'
        } else {
          el.style.left = pixel.x - 360 + 'px'
          el.style.top = pixel.y - 100 + 'px'
        }
      },
      disposeStrLengthFunc(str) {
        console.log(str.length)
        let newStr = str.length > 10 ? str.substring(0, str.length) + '...' : str
        // return
        return newStr
      },
      compParamStatusColor(val) {
        let retColor = ''
        switch (val) {
          case '适宜':
            retColor = '#21ad58'
            break
          case '偏高':
            retColor = '#f0545a'
            break
          case '偏低':
            retColor = '#f8b54c'
            break
          default:
            break
        }
        return retColor
      }
    },
    created() {
      console.log(this.data)
    }
  }
</script>

<style>
  .sampleToolTip {
    transition: 0.3s;
    width: 360px;
    height: 140px;
    line-height: 20px;
    /* background: white; */
    overflow: hidden;
    /* box-shadow: 5px 5px 5px 5px white; */
    color: #000000;
    text-align: center;
    /* padding: 10px; */
    position: absolute;
    margin-top: 80px;
    margin-left: -90px;
    z-index: 1000;
  }
  .sampleToolTip.active {
    background: rgba(29, 90, 236, 0.85);
    color: #fff;
  }

  .height_200 {
    height: 800px;
    /* padding: 0;
    box-shadow: none; */
  }

  .height_0 {
    height: 0px;
    /* padding: 0; */
    box-shadow: none;
  }

  .card {
    width: 350px;
    background-color: #fff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    overflow: hidden;
  }

  .header {
    letter-spacing: 2px;
    background-color: #1a2041;
    color: #fff;
    padding: 10px;
    text-align: center;
    font-size: 18px;
  }

  .body {
    padding: 10px;
  }

  .skill {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
  }

  .skill-name {
    width: 120px;
    font-size: 16px;
  }

  .skill-level {
    width: 160px;
    height: 10px;
    background-color: #eee;
    border-radius: 10px;
    overflow: hidden;
    margin-left: 6px;
  }

  .skill-percent {
    background-color: #333;
    height: 100%;
  }

  .skill-percent-number {
    margin-left: 0px;
    font-size: 16px;
  }

  /* 参数 */
  .param_box {
    /* display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-around; */
  }

  .p_param_title {
    text-align: left;
    padding-bottom: 5px;
    font-size: 14px;
    font-weight: bold;
    font-family: '黑体';
  }

  .param_item {
    position: relative;
  }

  .param_item .param_name {
    letter-spacing: 2px;
    width: 80px;
    display: inline-block;
    text-align: right;
    font-size: 14px;
    font-weight: bold;
    font-family: '黑体';
  }

  .param_item .param_value {
    font-weight: bold;
    /* font-family: '黑体'; */
  }

  .param_item .param_unit {
    color: gray;
    font-size: 12px;
    margin-left: 6px;
  }

  .param_item .param_status {
    display: inline-block;
    position: absolute;
    right: 10px;
    top: 20%;
    font-weight: bold;
    font-family: '黑体';
  }
</style>
